<!DOCTYPE html>
<html  xmlns:th="http://www.thymeleaf.org"  xmlns:shiro="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>司机信息管理</title>
	<link th:include="common/header::copy"/>
 <script type="text/javascript">

	var url;

	function formatEdit(val,row){
		return "<a href=\"javascript:openRoleChooseDialog('"+row.qq+"',"+row.id+")\"><img style='margin-top:4px' src='/images/edit.gif'/></a>";
	}

	
	function searchUser(){
		$("#dg").datagrid('load',{
			"vidcard":$("#s_vidcard").val(),
            "phone":$("#s_phone").val(),
            "idcard":$("#s_idcard").val(),
            "cname":$("#s_cname").val()
		});
	}
    function saveusersearchUser(){
        $("#dg").datagrid('load',{
            "username":$("#s_userName").val()
        });
    }

	function formatauth(value,row,index){
		if (value == 0){
			return '<span style="color: red">未认证</span>';

		}else{
			return '<span style="color: green">已认证</span>';
		}
	}

	function resetValue(){
        $("#id").val("");
        $("#cname").textbox('clear');
        $("#idcard").textbox('clear');
        $("#phone").textbox('clear');
        $("#telphone").textbox('clear');
        $("#accountBalances").textbox('clear');
        $("#vidcard").textbox('clear');
        $("#ename").textbox('clear');
        $("#rname").textbox('clear');
        $("#pic").removeAttr("src");
        $("#pic1").removeAttr("src");
	}
	
	function openUserAddDialog(){
		$("#pic1").removeAttr("src");
		$("#pic").removeAttr("src");
		$("#dlg").dialog("open").dialog("setTitle","添加司机信息");
	}

	function openUserModifyDialog(index){
		$("#dg").datagrid('selectRow',index);
		var row =$("#dg").datagrid('getSelected');
		if(row) {
			$("#dlg").dialog("open").dialog("setTitle", "修改司机信息");
            $("#pic").attr("src","/image/show?fileName="+row.licenseImg);
            $("#pic1").attr("src","/image/show?fileName="+row.idcardImg);
			$("#fm").form("load", row);
			$("#id").attr("readonly", "readonly");
		}
	}

    function formatop(val,row,index) {
        return '<a href="#" onclick="authentication(\'/veh/driver/auth\','+row.id+')">认证</a>' +      '&nbsp;&nbsp;'+
		'<a href="#" onclick="openUserModifyDialog('+index+')">修改</a>&nbsp;&nbsp;' +
            '<a href="#" onclick="deleteData(\'/veh/driver/delete\','+row.id+',id,\'数据已成功删除!\')">删除</a>&nbsp;&nbsp;';
    }

</script>
</head>
<body style="margin: 1px">
	<table id="dg" title="司机信息" class="easyui-datagrid"
	fitColumns="true" pagination="true" rownumbers="true" singleSelect="true"
	url="/veh/driver/list" fit="true" toolbar="#tb" method="Post" striped="true">
		<thead>
            <th field="id" width="20" align="center" hidden="true">编号</th>
			<th field="cname" width="20" align="center">司机姓名</th>
			<th field="vidcard" width="30" align="center">车牌号</th>
			<th field="idcard" width="50" align="center">身份证</th>
			<th field="phone" width="40" align="center">电话</th>
			<th field="ename" width="50" align="center">企业名称</th>
			<th field="isauth" width="50" align="center" formatter="formatauth">是否认证</th>
            <th field="op" width="20" align="center" formatter="formatop">操作</th>
        </thead>
	</table>
	
	<div id="tb">

	<div style="display: inline-block;">
		<a shiro:hasPermission="veh:driver:save" href="javascript:openUserAddDialog()" class="easyui-linkbutton" iconCls="icon-add" plain="true">添加</a>
		<a href="javascript:uploadidalogonline(2)" class="easyui-linkbutton" plain="true">导入</a>
		<a href="javascript:"  class="easyui-linkbutton"data-options="plain:true" onclick="$('#dg').datagrid('toExcel','dri.xls');">导出</a>
	</div>
 	<div shiro:hasPermission="veh:driver:list" style="display: inline-block;float:right">
            司机手机：<input type="text" id="s_phone" size="20" onkeydown="if(event.keyCode==13) searchUser()"/>
            身&nbsp;份&nbsp;证：<input type="text" id="s_idcard" size="20" onkeydown="if(event.keyCode==13) searchUser()"/>
            司机姓名：<input type="text" id="s_cname" size="20" onkeydown="if(event.keyCode==13) searchUser()"/>
            车&nbsp;牌&nbsp;号：<input type="text" id="s_vidcard" size="20" onkeydown="if(event.keyCode==13) searchUser()"/>
			<a href="javascript:searchUser()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
	</div>
	</div>

	<div shiro:hasPermission="veh:driver:save" id="dlg" class="easyui-dialog" style="width: 900px;height: 500px;padding: 10px 20px"
	closed="true" buttons="#dlg-buttons" data-options="onClose:function(){resetValue()}">
		<form id="fm" method="post">
            <input type="hidden" id="id" name="id">
			<table cellspacing="8px">
                <h2 style="border-bottom-color: #99cdff">司机信息</h2>
                <div style="margin-bottom:10px">
                    <input name="cname" id="cname" class="easyui-textbox" required="true" label="姓名:" style="width:300px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <input name="idcard" id="idcard" class="easyui-textbox" required="true" label="身份证:" style="width:300px">
                </div>
				<div>
					<tr>
					<td><a href="javascript:uploadidalogonline(1)">驾照上传</a></td>

					<td>
						<img id="pic" name="pic" style="width: 100px;height: 100px">
						<input id="licenseImg" name="licenseImg" hidden>
					</td>
				</tr>
					<tr>
						<td><a href="javascript:uploadidalogonline(3)">身份证上传</a></td>
						<td>
							<img id="pic1" name="pic1" style="width: 100px;height: 100px">
							<input id="idcardImg" name="idcardImg" hidden>
						</td>
					</tr>
				</div>
               <!-- <div style="margin-bottom:10px">
                    <input  name="licenseImg" id="licenseImg" class="easyui-filebox" label="驾照上传:"  data-options="prompt:'上传图片...'" style="width:300px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <input  name="idcardImg" id="idcardImg" class="easyui-filebox" label="身份证上传:"  data-options="prompt:'上传图片...'" style="width:300px">&nbsp;
                </div>-->
                <div style="margin-bottom:10px">
                    <input name="phone" id="phone" class="easyui-textbox" required="true" label="电话:" style="width:300px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <input name="telphone" id="telphone" class="easyui-textbox" required="true" label="预留电话:" style="width:300px">
                </div>
                <div style="margin-bottom:10px">
<!--
                    <input name="vidcard" id="vidcard" class="easyui-textbox" required="true" label="车牌号:" style="width:300px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
-->

					<input shiro:hasPermission="veh:driver:getAll" class="easyui-combobox"
						   label="车牌号:"
						   style="width:300px"
						   name="vidcard"
						   data-options="
					url:'/veh/driver/getAll',
					method:'get',
					valueField:'id',
					textField:'vidcard',
					panelHeight:'auto'">

                    <input name="accountBalances" id="accountBalances" class="easyui-textbox" required="true" label="账户余额:" style="width:300px">
                </div>
			</table>
		</form>
	</div>
	
	<div id="dlg-buttons">
		<a shiro:hasPermission="veh:driver:save" href="javascript:save('/veh/driver/save')" class="easyui-linkbutton" iconCls="icon-ok" >保存</a>
		<a href="javascript:closeDialog('#dlg1')" class="easyui-linkbutton" iconCls="icon-cancel" >关闭</a>
	</div>


	<div id="dlg2" class="easyui-dialog" style="width: 500px;height: 350px;"
	closed="true" buttons="#dlg-buttons2">
	    <input type="hidden" id="userId" name="userId"/>
		<table id="dg2"  class="easyui-datagrid" fitColumns="true" fit="true">
		<thead>
		    <th field="cb" checkbox="true" align="center"></th>
			<th field="id" width="20" align="left" hidden="true">编号</th>
			<th field="cname" width="100" align="left">角色名称</th>
			<th field="remark" width="200" align="left">备注</th>
		</thead>
	</table>
	</div>

	<div id="dlg-buttons2">
		<a href="javascript:saveRoleSet()" class="easyui-linkbutton" iconCls="icon-ok" >保存</a>
		<a href="javascript:closeDialog('#dlg2')" class="easyui-linkbutton" iconCls="icon-cancel" >关闭</a>
	</div>
	<div id="uploadonlineinfo" class="easyui-dialog" style="width:380px;padding:10px 40px" closed="true">
		<form id="fam" method="post" enctype="multipart/form-data">
			<input type="file" id="file" name="file">
			<input type="hidden" id="flag" name="flag">
		</form>

		<div data-options="region:'south',border:false" style="text-align:center;padding:5px 0 0;">
			<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)"
			   onclick="uploadonline();" style="width:80px">上传</a>
		</div>
	</div>
	<script type="text/javascript">

		function uploadidalogonline(flag) {
			$('#uploadonlineinfo').dialog('open').dialog('setTitle', '文件上传');
			$("#flag").val(flag);

		}

		function uploadonline() {
			var file = $("#file")[0].files[0];
			var flag = $("#flag").val();
			var url;
			if (file.name == "") {
				alert("请先选择文件");
				return false;
			}
			if (flag == 1 || flag == 3) {
				url = "/image/upload";
				if (!file.name.match(/.jpg|.jpeg|.gif|.png|.bmp/i)) {

					alert("文件格式错误");
					return false;
				}
			} else {
				url = "/veh/driver/excelImport";
				if (!file.name.match(/.xls|.xlsx/i)) {
					alert("文件格式错误");
					return false;
				}
			}
			var form = new FormData();
			form.append("file", file);
			var picget = "/image/show?fileName=";
			$.ajax({
				url: url,
				type: "post",
				data: form,
				processData: false,
				contentType: false,
				success: function (data) {
					$('#uploadonlineinfo').window('close');
					if (flag == 1) {
						$("#pic").attr("src", picget+data.info);
						$("#licenseImg").val(data.info)
					}
					if(flag == 3){
						$("#pic1").attr("src", picget+data.info);
						$("#idcardImg").val(data.info)
					}
					console.log(data);
				},
				error: function (e) {
					console.log(e);
				}
			});
		}
	</script>
</body>
</html>